module.exports = {
	prefix: "/lottery",
	get: {
		"/by_id/:lottery_id": function() {
			var lottery_id = this.params.lottery_id;
			var query = this.request.query;
			var bus_id = query.bus_id;
			if (!bus_id) {
				throwCusError("参数错误")
			}
			var bus = BusCon.get(bus_id);
			if (!bus) {
				throwCusError("找不到指定商家")
			}
			this.body = ResponObj("json", bus.getLottery(lottery_id, query.is_with_visitor_map))
		},
		"/list": function() {
			var query = this.request.query;
			var bus_id = query.bus_id;
			if (!bus_id) {
				throwCusError("参数错误")
			}
			var bus = BusCon.get(bus_id);
			if (!bus) {
				throwCusError("找不到指定商家")
			}
			if (query.with_award_content_detail) {
				var res = bus.getLotteryDetailList(query.is_with_visitor_map);
			} else {
				res = bus.getLotteryList(query.is_with_visitor_map);
			}
			try {
				var user = role.getUser(this);
				res.forEach(function(lottery) {
					lottery._can_user_draw_lottery = !lottery.joiner_map[user._id];
					if (!lottery._can_user_draw_lottery) {
						lottery.awards.some(function(award) {
							if (award.winner_list.indexOf(user._id) !== -1) {
								award = $Object.clone(award);
								delete award.winner_list;
								lottery._user_win_something = award;
							}
						})
					}
				});
			} catch (e) {}
			this.body = ResponObj("json", res)
		}
	}
}
var role = require("./role");
var BusCon = require("../../core/bus/_con");
var UserCon = require("../../core/user/_con");
var GoodsCon = require("../../core/goods/_con");
var AchCon = require("../../core/ach/_con");
var db = require("../../core/db/index");
var config = require("../../core/_include/config");
var $Object = require("../../core/_include/$.Object");
var ResponObj = require("../_include/responObj");